package servlets;

import java.awt.image.DataBufferByte;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import util.StringConstants;

import database.DatabaseOperations;

/**
 * Servlet implementation class ViewClientJobs
 */
@WebServlet("/ViewClientJobs")
public class ViewClientJobs extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private DatabaseOperations databaseOperations;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ViewClientJobs() {
        super();
        databaseOperations = new DatabaseOperations();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String title = "Database Result";
		String docType = "<!doctype html public \"-//w3c//dtd html 4.0 "
				+ "transitional//en\">\n";
		out.println(docType + "<html>\n" + "<head><title>" + title
				+ "</title></head>\n" + "<body bgcolor=\"#f0f0f0\">\n"
				+ "<h1 align=\"center\">" + title + "</h1>\n");
		// Set response content type
		System.out.println(request.getParameter("clientName"));
		for(String s: databaseOperations.getJobsForUser(request.getParameter("clientName"))){
			out.println(s);
			out.println("<br>");
			out.println("<br>");
		}
		
		out.println("<a href='"+StringConstants.homepage+"'> Go to home page </a>");
		out.println("</body></html>");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
